package org.ccay.log.webtrace.impl;

import org.apache.log4j.Level;
import org.apache.log4j.spi.Filter;
import org.apache.log4j.spi.LoggingEvent;

/**
 * WebTrace 中用到的日志过滤器, 用于将非特定用户的DEBUG日志去除．
 * 
 * @author chaowangbang
 * @since 2012-6-5
 */
public final class WebTraceNdcFilter extends Filter {

	/**
	 * 获取唯一实例
	 * 
	 * @return
	 */
	public static WebTraceNdcFilter getInstance() {
		return new WebTraceNdcFilter();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * org.apache.log4j.spi.Filter#decide(org.apache.log4j.spi.LoggingEvent)
	 */
	@Override
	public int decide(LoggingEvent event) {
		// begin modify by zwx304259 SP22 升级到log4j2.0该过滤器用不到
		/*if (!WebTraceStatusManager.isWebTraceEnabled || event.getLevel().isGreaterOrEqual(Level.INFO)) {
			return Filter.NEUTRAL;
		}

		Thread currentThread = Thread.currentThread();
		String currentThreadName = currentThread.getName();

		if (currentThreadName != null) {
			return (currentThreadName.indexOf(
					"-" + WebTraceStatusManager.userAccount2Trace + "-") != -1) ? Filter.ACCEPT
					: Filter.DENY;
		}*/
		// end modify by zwx304259 SP22 
		return Filter.DENY;
	}

}
